import {
  VuexModule,
  Module,
  Mutation,
  Action,
  getModule
} from 'vuex-module-decorators'

// import {
//   getSidebarStatus,
//   setSidebarStatus,
//   setLanguage
// } from '@/utils/cookies'

import store from '@/store'

// import { getLocale } from '@/lang'

export enum DeviceType {
  Mobile,
  Desktop
}

export interface IAppState {

  device: DeviceType
  sidebar: {
    opened: boolean
    withoutAnimation: boolean
  }
  // language: string,
  selectBar:number
}

@Module({ dynamic: true, store, name: 'app' })

class App extends VuexModule implements IAppState {

  public sidebar = {
    // opened: getSidebarStatus() !== 'closed',
    opened:true,
    withoutAnimation: false
  }

  public device = DeviceType.Desktop
   public selectBar=0
  // public language = getLocale()



   @Mutation
  private SELECT_BAR(selectBar: number) {

     this.selectBar=selectBar
     
     console.log('this.selectBarVuex',this.selectBar)
    // this.sidebar.opened = !this.sidebar.opened
    // this.sidebar.withoutAnimation = withoutAnimation
    // if (this.sidebar.opened) {
    //   setSidebarStatus('opened')
    // } else {
    //   setSidebarStatus('closed')
    // }
  }
  @Mutation
  private TOGGLE_SIDEBAR(withoutAnimation: boolean) {
    // this.sidebar.opened = !this.sidebar.opened
    // this.sidebar.withoutAnimation = withoutAnimation
    // if (this.sidebar.opened) {
    //   setSidebarStatus('opened')
    // } else {
    //   setSidebarStatus('closed')
    // }
  }

  @Mutation
  private CLOSE_SIDEBAR(withoutAnimation: boolean) {
    // this.sidebar.opened = false
    // this.sidebar.withoutAnimation = withoutAnimation
    // setSidebarStatus('closed')
  }

  @Mutation
  private TOGGLE_DEVICE(device: DeviceType) {
    this.device = device
  }

  @Mutation
  private SET_LANGUAGE(language: string) {
    // this.language = language
    // setLanguage(this.language)
  }

  @Action
  public ToggleSideBar(withoutAnimation: boolean) {
    this.TOGGLE_SIDEBAR(withoutAnimation)
  }

  @Action
  public CloseSideBar(withoutAnimation: boolean) {
    this.CLOSE_SIDEBAR(withoutAnimation)
  }

  @Action
  public ToggleDevice(device: DeviceType) {
    this.TOGGLE_DEVICE(device)
  }

  @Action
  public SetLanguage(language: string) {
    this.SET_LANGUAGE(language)
  }

  // 首页 topbar
  @Action
  public selectBarAction(selectBar: number) {
    this.SELECT_BAR(selectBar)
  }
}

export const AppModule = getModule(App)
